package com.test.sdk.provider;

import com.test.sdk.provider.exception.SdkExceptionHandler;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;
import org.springframework.web.client.RestTemplate;

@SpringBootApplication
@MapperScan("com.test.sdk.provider.dao")
@ServletComponentScan//让springboot去扫描servlet注解
@ComponentScan(basePackages = "com.test.sdk.provider")
public class SdkProviderApplication {

    public static void main(String[] args) {
        SpringApplication.run(SdkProviderApplication.class, args);
    }


    @Bean
    public SdkExceptionHandler sdkExceptionHandler() {
        return new SdkExceptionHandler();
    }

    @Bean
    public RestTemplate restTemplate(){
        return new RestTemplate();
    }
    //解决中文乱码
    @Bean
    public RedisTemplate<String, String> redisTemplate(RedisConnectionFactory factory) {
        StringRedisTemplate template = new StringRedisTemplate();
        template.setConnectionFactory(factory);
// key序列化
        template.setKeySerializer(new StringRedisSerializer());
        //val实例化
        template.setValueSerializer(new GenericJackson2JsonRedisSerializer());
        return template;
    }
}
